﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using Common;

namespace MODEL
{
    public class ValveControl : ViewModelBase
    {
        public string Id { get; set; }
        public string Operator { get; set; }
        public DateTime AddTime { get; set; }
        public TimeSpan Exec_TimeSpan { get; set; } = DateTime.Now.TimeOfDay;

        private DateTime m_Exec_Time = DateTime.Now;
        public DateTime Exec_Time
        {
            get{return this.m_Exec_Time;}
            set
            {
                this.m_Exec_Time = value;
                this.Exec_TimeSpan = this.m_Exec_Time.TimeOfDay;
            }
        }
        public int Msg_Id { get; set; }
        public int Valve_No { get; set; }
        public int OrderType { get; set; }
        public int Order { get; set; }

        private int m_Time1 = 30;
        public int Time1
        {
            get { return this.m_Time1; }
            set { this.m_Time1 = value; base.RaisePropertyChanged(() => Time1); }
        }
        public int Time2 { get; set; }
        public int Time3 { get; set; }
        public int Status { get; set; } = 1;
        public DateTime Update_Time { get; set; }
        public int HasOper { get; set; } = 1;
        public StationInfo StationInfo { get; set; } = new StationInfo();

        public StationOperateTypeEnum OperateType => StationInfo?.GetOperateTypeEnum(this.Valve_No) ?? StationOperateTypeEnum.NoOperate;
   
        public bool IsInProcess => this.Status == 1 && DateTime.Now< this.Exec_Time.AddMinutes(Time1) && HasOper > 0;

        public string Name => $"阀门{this.Valve_No.ToString()}({this.OperateType.GetDescription()})";

        public string FinishStr => IsInProcess ? "完成" : "未完成";

        public ProcessItem ConvertToProcessItem()
        {
            return new ProcessItem
            {
                Title = Name,
                BeginTime = this.Exec_Time,
                ExcuteTime = TimeSpan.FromMinutes(this.Time1),
                IsOpen = this.IsInProcess
            };
        }
    }
}
